//
//  UIBarButton + extension.swift
//  czWB
//
//  Created by Qing on 2018/6/5.
//  Copyright © 2018年 成哥哥. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    

    /// 便利构造函数，可以设置抬头，字体大小，执行对象，执行方法，是否返回按钮
    ///
    /// - Parameters:
    ///   - title: 抬头
    ///   - fontSize: 字体大小
    ///   - target: 执行对象
    ///   - action: 执行方法
    ///   - isBack: 是否返回按钮
    convenience init(title: String, fontSize: CGFloat = 16, target: Any, action: Selector, isBack: Bool = false) {
        
        let btn = UIButton.cz_textButton(title: title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightColor: UIColor.orange)
        
        if isBack {
            
            let imageName = "navigationBar_back"
            btn.setImage(UIImage(named: imageName), for: UIControl.State(rawValue: 0))
            btn.setImage(UIImage(named: imageName + "_highlight"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: UIControl.Event.touchUpInside)
        
//        便利构造陈函数需要使用self.init()实例化
        self.init(customView: btn)
        
    }
}
